<?php


namespace app\common\service\store;


use app\admin\model\store\SeckillConfig;
use app\common\controller\AdminController;
use app\common\service\BaseService;

class SeckillConfigService extends BaseService
{

    /**
     * Author:YangXinPeng
     * 秒杀配置生成
     * @param $params
     * @return array
     */
    public static function save($params)
    {
        unset($params['file']);
        if (array_key_exists('status', $params)) {
            $params['status'] = 0;
        }
        $params['start_time'] = strtotime($params['start_time']);
        $params['end_time'] = strtotime($params['end_time']);
        try {
            $flag = SeckillConfig::create($params);
        } catch (\Exception $e) {
            return self::fail('保存失败');
        }
        return $flag ? self::success('保存成功') : self::fail('保存失败');
    }

    /**
     * Author:YangXinPeng
     * 根据ID查询秒杀配置
     * @param $id
     * @return array|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function idFind($id)
    {
       $config = SeckillConfig::find($id);
       $config && $config = $config->toArray();
       return $config;
    }
}